import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';

import { CreateUserRequestDto } from '../dto/requests/create-user.dto';
import { UpdateUserRequestDto } from '../dto/requests/update-user.dto';
import { UserBasicInfoResponseDto } from '../dto/responses/user-basic-info.dto';
import { UsersService } from '../services/users.service';

@ApiTags('users')
@Controller('users')
export class UsersController {
  constructor(private readonly userService: UsersService) {}

  @Get()
  async list(): Promise<string> {
    return 'user list';
  }

  @Get('count')
  async count(): Promise<number> {
    return this.userService.count();
  }

  @Get(':id/status')
  async status(@Param('id') id: string): Promise<string> {
    return `status of user ${id}`;
  }

  @ApiOkResponse({ type: UserBasicInfoResponseDto })
  @Get(':id')
  async get(@Param('id') id: string): Promise<UserBasicInfoResponseDto> {
    return {
      id: id,
      username: 'username',
      fullName: 'full name',
      enabled: true,
    };
  }

  @Post()
  async create(@Body() dto: CreateUserRequestDto): Promise<string> {
    console.dir(dto);
    return 'user created';
  }

  @Patch(':id')
  async update(@Param('id') id: string, @Body() dto: UpdateUserRequestDto): Promise<string> {
    console.log('Updating user', id, dto);
    return `user ${id} updated`;
  }

  @Delete(':id')
  async delete(@Param('id') id: string): Promise<string> {
    return `user ${id} deleted`;
  }
}
